<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        html, body {
            height: 100%;
        }
        .box{
            position: absolute;
            top: 0;
            left: 0;
            width: 100px;
            height: 100px;
            background-color: pink;
            transition: all 0.7s;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <script>
        let box = document.querySelector('.box');
        function toLeft(cb) {
            console.log('右移');
            let timer = setTimeout((cb) => {
                box.style.left = '300px';
                cb();
            },2000);
            // console.log(box.style.left);
            // if(box.style.left === '300px') {
            //     console.log('0000');
            //     clearTimeout(timer);
            //     cb();
            // }
            
        }
        // toLeft(function () {});

        function toRight(cb) {
            console.log('左移');
            let timer = setTimeout((cb) => {
                box.style.left = 0;
                cb();
            },2000);
            // if( box.style.left === 0) {
            //     clearTimeout(timer);
            //     cb();
            // }
            
        }
        function toTop(cb) {
            console.log('下移');
            let timer = setTimeout((cb) => {
                box.style.top = '300px';
                cb()
            },2000)
            // if (box.style.top === '300px') {
            //     clearTimeout(timer);
            //     cb();
            // }
            
        }
        toLeft(function() {
            console.log("向右执行完毕了");
            toTop(function() {
                toRight(function() {

                }) 
            })
        })
    </script>
</body>
</html>